/**
 * 泰波那契序列 Tn 定义如下： 
 *
 * T0 = 0, T1 = 1, T2 = 1, 且在 n >= 0 的条件下 Tn+3 = Tn + Tn+1 + Tn+2
 *
 * 给你整数 n，请返回第 n 个泰波那契数 Tn 的值。
 */
public class Test1137 {
    public int tribonacci(int n) {
        if (n < 2) return n;
        if (n == 2) return 1;
        int n0 = 0;
        int n1 = 1;
        int n2 = 1;
        int ret = 0;
        for (int i = 3; i <= n; i++) {
            ret = n0 + n1 + n2;
            n0 = n1;
            n1 = n2;
            n2 = ret;
        }
        return ret;
    }
}
